/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
*    1. Redistributions of source code must retain the above copyright notice, this list of
*       conditions and the following disclaimer.
*
*    2. Redistributions in binary form must reproduce the above copyright notice, this list
*       of conditions and the following disclaimer in the documentation and/or other materials
*       provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/

/*
 * CardSelector.java
 *
 * Created on Feb 18, 2010, 2:49:03 PM
 */

package mage.client.deckeditor;

import java.awt.Cursor;
import mage.Constants.Zone;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.client.cards.BigCard;
import mage.client.cards.CardsList;
import mage.filter.Filter.ComparisonScope;
import mage.filter.FilterCard;
import mage.sets.AlaraReborn;
import mage.sets.Conflux;
import mage.sets.Magic2010;
import mage.sets.Planechase;
import mage.sets.ShardsOfAlara;
import mage.sets.Tenth;
import mage.sets.Worldwake;
import mage.sets.Zendikar;
import mage.view.CardsView;

/**
 *
 * @author BetaSteward_at_googlemail.com
 */
public class CardSelector extends javax.swing.JPanel {

	private Cards cards = new CardsImpl(Zone.OUTSIDE);
	private FilterCard filter = new FilterCard();
	private BigCard bigCard;
	
    /** Creates new form CardSelector */
    public CardSelector() {
        initComponents();
    }

	public void loadCards(BigCard bigCard) {
		this.bigCard = bigCard;
		this.cards.clear();
		cards.addAll(AlaraReborn.getInstance().createCards());
		cards.addAll(Conflux.getInstance().createCards());
		cards.addAll(Magic2010.getInstance().createCards());
		cards.addAll(Planechase.getInstance().createCards());
		cards.addAll(ShardsOfAlara.getInstance().createCards());
		cards.addAll(Tenth.getInstance().createCards());
		cards.addAll(Worldwake.getInstance().createCards());
		cards.addAll(Zendikar.getInstance().createCards());
		filter.setUseColor(true);
		filter.getColor().setBlack(true);
		filter.getColor().setBlue(true);
		filter.getColor().setGreen(true);
		filter.getColor().setWhite(true);
		filter.getColor().setRed(true);
		filter.setColorless(true);
		filter.setUseColorless(true);
		filter.setNotColor(false);
		filter.setScopeColor(ComparisonScope.Any);
		filterCards();
	}

	private void filterCards() {
		try {
			setCursor(new Cursor(Cursor.WAIT_CURSOR));
			this.cardsList1.loadCards(new CardsView(cards.getCards(filter)), bigCard, null);
		}
		finally {
			setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
		}
	}

	public CardsList getCardsList() {
		return this.cardsList1;
	}

	public Cards getCards() {
		return cards;
	}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        rdoRed = new javax.swing.JRadioButton();
        rdoGreen = new javax.swing.JRadioButton();
        rdoBlue = new javax.swing.JRadioButton();
        rdoBlack = new javax.swing.JRadioButton();
        rdoWhite = new javax.swing.JRadioButton();
        rdoColorless = new javax.swing.JRadioButton();
        cardsList1 = new mage.client.cards.CardsList();

        jToolBar1.setRollover(true);

        rdoRed.setSelected(true);
        rdoRed.setText("Red ");
        rdoRed.setFocusable(false);
        rdoRed.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        rdoRed.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        rdoRed.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdoRedActionPerformed(evt);
            }
        });
        jToolBar1.add(rdoRed);

        rdoGreen.setSelected(true);
        rdoGreen.setText("Green ");
        rdoGreen.setFocusable(false);
        rdoGreen.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        rdoGreen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        rdoGreen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdoGreenActionPerformed(evt);
            }
        });
        jToolBar1.add(rdoGreen);

        rdoBlue.setSelected(true);
        rdoBlue.setText("Blue ");
        rdoBlue.setFocusable(false);
        rdoBlue.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        rdoBlue.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        rdoBlue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdoBlueActionPerformed(evt);
            }
        });
        jToolBar1.add(rdoBlue);

        rdoBlack.setSelected(true);
        rdoBlack.setText("Black ");
        rdoBlack.setFocusable(false);
        rdoBlack.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        rdoBlack.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        rdoBlack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdoBlackActionPerformed(evt);
            }
        });
        jToolBar1.add(rdoBlack);

        rdoWhite.setSelected(true);
        rdoWhite.setText("White ");
        rdoWhite.setFocusable(false);
        rdoWhite.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        rdoWhite.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        rdoWhite.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdoWhiteActionPerformed(evt);
            }
        });
        jToolBar1.add(rdoWhite);

        rdoColorless.setSelected(true);
        rdoColorless.setText("Colorless");
        rdoColorless.setFocusable(false);
        rdoColorless.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        rdoColorless.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        rdoColorless.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdoColorlessActionPerformed(evt);
            }
        });
        jToolBar1.add(rdoColorless);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 825, Short.MAX_VALUE)
            .addComponent(cardsList1, javax.swing.GroupLayout.DEFAULT_SIZE, 825, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(cardsList1, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

	private void rdoGreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdoGreenActionPerformed
		filter.getColor().setGreen(this.rdoGreen.isSelected());
		filterCards();
	}//GEN-LAST:event_rdoGreenActionPerformed

	private void rdoBlackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdoBlackActionPerformed
		filter.getColor().setBlack(this.rdoBlack.isSelected());
		filterCards();
	}//GEN-LAST:event_rdoBlackActionPerformed

	private void rdoWhiteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdoWhiteActionPerformed
		filter.getColor().setWhite(this.rdoWhite.isSelected());
		filterCards();
	}//GEN-LAST:event_rdoWhiteActionPerformed

	private void rdoRedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdoRedActionPerformed
		filter.getColor().setRed(this.rdoRed.isSelected());
		filterCards();
	}//GEN-LAST:event_rdoRedActionPerformed

	private void rdoBlueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdoBlueActionPerformed
		filter.getColor().setBlue(this.rdoBlue.isSelected());
		filterCards();
	}//GEN-LAST:event_rdoBlueActionPerformed

	private void rdoColorlessActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdoColorlessActionPerformed
		filter.setColorless(this.rdoColorless.isSelected());
		filterCards();
	}//GEN-LAST:event_rdoColorlessActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private mage.client.cards.CardsList cardsList1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JRadioButton rdoBlack;
    private javax.swing.JRadioButton rdoBlue;
    private javax.swing.JRadioButton rdoColorless;
    private javax.swing.JRadioButton rdoGreen;
    private javax.swing.JRadioButton rdoRed;
    private javax.swing.JRadioButton rdoWhite;
    // End of variables declaration//GEN-END:variables

}
